package com.zhss.demo.concurrent;

import java.util.concurrent.locks.LockSupport;

/**
 * 线程挂起
 */
public class ParkDemo {

    public static void main(String[] args) {
        Thread thread1 = new Thread() {
            @Override
            public void run() {
                System.out.println("线程挂起之前的操作");
                LockSupport.park();
                System.out.println("线程唤醒之后的操作");
            }
        };
        thread1.start();

        new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    try {
                        Thread.sleep(1000);
                        System.out.println("等待"+ (i+1) +"秒");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                LockSupport.unpark(thread1);
            }
        }.start();

    }

}
